import service from "@/utils/request";
import { setToken } from "@/utils/jwt";
import router from "@/router";
import { ElMessage } from "element-plus";

export function loginService(userAccount, password) {
  return service({
    url: "/sysUser/login",
    method: "post",
    data: {
      userAccount,
      password,
    },
  });
}

export function loginServiceChange(userAccount, password) {
  console.log("loginServiceChange:" + userAccount + password);
  let data = {
    userAccount: userAccount,
    password: password,
  };
  service
    .post("/sysUser/login", data)
    .then((loginResult) => {
      if (loginResult.code == 1000) {
        ElMessage({
          message: "登陆成功",
          type: "success",
        });
        router.push("/oj/layout");
        setToken(loginResult.data);
      } else {
        ElMessage({
          message: loginResult.msg,
          type: "error",
        });
      }
    })
    .catch((err) => {
      console.error("请求失败:", err);
    });
}
